#!/bin/bash
# create_leishi_service.sh
# 用于创建 leishi.service（如果不存在），重新加载 systemd 配置，并设置服务开机自启

SERVICE_FILE="/etc/systemd/system/leishi.service"

if [ ! -f "$SERVICE_FILE" ]; then
    echo "Creating $SERVICE_FILE ..."
    sudo tee "$SERVICE_FILE" > /dev/null << 'EOF'
[Unit]
Description=Leishi Program Service
After=network.target

[Service]
ExecStart=/home/linaro/zhuke/leishi/main.bin
WorkingDirectory=/home/linaro/zhuke/leishi
Restart=always
RestartSec=5
User=linaro

[Install]
WantedBy=multi-user.target
EOF

    echo "Reloading systemd configuration..."
    sudo systemctl daemon-reload

    echo "Enabling leishi.service to start at boot..."
    sudo systemctl enable leishi.service

    echo "Service file created and enabled."
else
    echo "$SERVICE_FILE already exists."
fi

#sed -i -e 's/\r$//' service.sh